//
//  FCEmptyView.m
//  FuChengCompany
//
//  Created by fly on 2019/2/19.
//  Copyright © 2019年 fly. All rights reserved.
//

#import "FCEmptyView.h"
#import "WJCDefine.h"
@interface FCEmptyView ()

@property (nonatomic, strong) UIView *customView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *actionButton;

@end

@implementation FCEmptyView

- (void)prepare
{
    [super prepare];
}

/** 快速创建立即登录空View */
+ (instancetype)emptyViewWithTarget:(id)target action:(SEL)action
{
    return [self emptyViewWithTitle:@"当前未登录，请先登录" imageName:@"ic_empty_photo_login" btnTitle:@"立即登录" target:target action:action];
}

/**
 创建空View
 
 @param title 标题
 @param imageName 图片名
 @param btnTitle 按钮标题
 */
+ (instancetype)emptyViewWithTitle:(NSString *)title imageName:(id)imageName btnTitle:(NSString *)btnTitle target:(id)target action:(SEL)action
{
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WJCScreenW, 500)];
    UIImageView *iconImageView = [[UIImageView alloc] init];
    if ([imageName isKindOfClass:[UIImage class]]) {
        iconImageView.image =imageName;
    }else if ([imageName isKindOfClass:[NSString class]]){
         iconImageView.image = [UIImage imageNamed:imageName];
    }
   
    iconImageView.frame = CGRectMake(0, 0, 120, 120);
    iconImageView.contentMode=UIViewContentModeScaleAspectFit;
    [iconImageView sizeToFit];
    iconImageView.centerX = customView.centerX;
    [customView addSubview:iconImageView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(iconImageView.frame) + 24, WJCScreenW - 32, 21)];
    titleLabel.textColor = HEXC(0x999999);
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.centerX = customView.centerX;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = title;
    [customView addSubview:titleLabel];
    
    CGFloat btnWidth = 88;
    if ([btnTitle isEqualToString:@"添加上下游关系"] || [btnTitle isEqualToString:@"重新加载通讯录"] || [btnTitle isEqualToString:@"重新加载关系"]) {
        btnWidth = 176;
    }
    UIButton *actionButton = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLabel.frame) + 40, WJCScreenW - btnWidth, 42)];
    actionButton.backgroundColor = HEXC(0x6291F6);
    actionButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    if (isEnterprise) {
//        WJCSETLRViewBorderRadius(actionButton,4);
//    }else{
//        WJCSETLRViewBorderRadius(actionButton,21);
//    }
    WJCSETLRViewBorderRadius(actionButton,4);
    
    actionButton.centerX = customView.centerX;
    [actionButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [actionButton setTitle:btnTitle forState:UIControlStateNormal];
    [customView addSubview:actionButton];
    
    if (!btnTitle.length) {
        actionButton.hidden = YES;
    }
    
    customView.height = CGRectGetMaxY(actionButton.frame) + 100;
    
    FCEmptyView *emptyViewDiy = [FCEmptyView emptyViewWithCustomView:customView];
    
    return emptyViewDiy;
}

- (void)setEmptyViewY:(NSInteger)emptyViewY
{
    _emptyViewY = emptyViewY;
    
    self.customView.y = emptyViewY;
}
@end
